package com.felight.ems.hr;
import java.util.*;

public class Calculator{
	public final static double PI=3.142;
	
	public static void main(String[] args){
		int[][] matrix=new int[2][3];
		int[] array={5, 8, 1, 3, 2};
		char[] arr={'a','r','t','e','i'};
	
		areaOfRectangle(4.5,7.5);
		areaOfCircle(20.0);
		System.out.println("the fibonacci series are:");
		Fibonacci(10);
		
		sumOfArray(array);
		getMaxOfArray(array);
		reverseArray(array);
		countVowels(arr);
		generatePrimeArray(1,10);
		//generateRandomIntMatrix(matrix);
		printMatrix(matrix);
	}

	public static double areaOfRectangle(double height,double width){
		double h=height;
		double w=width;
		double area=0.0;
		if(height>=0){
			if(width>=0)
				area=h*w;
		}
		return area;
	}
	
	public static double areaOfCircle(double r){
	double area=0.0;
		if(r>=0)
			area=r*r*PI;	
		return area;
	}
	
	public static int[] Fibonacci(int num){
		int[] result=new int[20];
		int[] res = new int[result.length];
		result[0]=0;
		result[1]=1;
		for(int i=2;i<num;i++){
			result[i]=result[i-1]+result[i-2];
		}
		return result;
	}
	
	/*public int even(int num){
	
		if(num%2==0){
			System.out.println("the num"+num+"is even");
		}
		else{
			System.out.println("the num"+num+"is odd");
		}
		return num;
	}*/
	
	public static void printCharArray(char[] array){
		for(int i=0;i<array.length;i++)
			System.out.println(array[i]+",");
	}
	
	public static void printIntArray(int[] array){
		for(int i=0;i<array.length;i++)
			System.out.println(array[i]+",");
	}
	
	public static long sumOfArray(int[] array){
		long sum = 0;
		for(int i =0;i<array.length;i++)
			sum = sum+array[i];
		return sum;
	}
	
	public static int[] generateRandomIntArray(int size){
		int[] result = new int[size];
		for(int i=0;i<size;i++)
			result[i]=(int) (Math.random()*100);
		return result;
	}
	
	public static int[] generateRandomIntMatrix(int[][] matrix){
		int[] result = new int[matrix.length];
		int row=0,column=0;
		for(row=0;row<matrix.length;row++){
			for( column=0;column<matrix[row].length;column++){
				matrix[row][column]=(int) (Math.random()*100);	
			}
		}
		System.out.println(matrix[row][column]);
		return result;
	}
	
	public static double[] generateRandomDoubleArray(int size){
		double[] result = new double[size];
		for (int i=0;i<size;i++)
			result[i]=Math.random()*100;
		return result;
	}
	
	public static char[] generateRandomCharArray(int size){
		char temp;
		char[] result = new char[size];
		int i=0;
		while(i<size){
			temp=(char)(Math.random()*100);
			if ((temp >= 'a' && temp <= 'z')||(temp >='A' && temp <='Z')){
				result[i++]=temp;
			}
		}
		return result;
	}
	
	public static int getMaxOfArray(int[] array){
		int max=0;
		for(int i=0;i<array.length;i++)
			if(max<array[i])
				max=array[i];
		return max;
	}
	
	public static int[] reverseArray(int[] array){
		int[] rev = new int[array.length];
		for(int i=0;i<array.length;i++){
			rev[array.length-i-1]=array[i];
		}
		return rev;
	}
	
	public static int countVowels(char[] array){
		int count = 0;
		for(int i=0;i<array.length;i++){
			if(array[i]=='a'||array[i]=='e'||array[i]=='i'||array[i]=='o'||array[i]=='u'||array[i]=='A'||array[i]=='E'||array[i]=='I'||array[i]=='O'||array[i]=='U')
				count++;
		}
			return count;
	}
	
	public static int[] generateEvenArray(int from,int to){
		int[] result = new int[50];
		for(int i=from,j=0;i<=to;i++,j++)
			if(i%2==0)//for odd number if(!(i%2==0))
				result[j]=i;
			else
				j--;
		return result;
	}
	
	public static int[] generatePrimeArray(int from,int to){
		int[] arr = new int[50];
		for(int i=from,j=0;i<=to;i++,j++)
			if(isPrime(i)){
				arr[j]=i;
				System.out.println(arr[j]);
			}
			else
				j--;
			return arr;
	}
	
	public static boolean isPrime(long num){
		boolean result=false;
		long count=0;
		long i=2;
		while(i<=num/2){
			if(num %i==0)
				count++;
			i++;
		}
		if(count==0 && num!=1 && num!=0)
			result= true;
		return result;
	}
	
	public static void printMatrix(int[][] matrix){
		int i,j;
		for(i=0;i<matrix.length;i++){
			for(j=0;j<matrix.length;j++){
				System.out.println(matrix[i][j]+" ");
			}
			System.out.println(" ");
		}
	}
	
	public static long sumMatrix(int[][] matrix){
		long sum=0;
		for(int i=0;i<matrix.length;i++)
			for(int j=0;j<matrix[i].length;j++)
				sum=sum+matrix[i][j];
		return sum;
	}
	
	public static int[] sumRow(int[][] matrix){
		int sum[] = new int[matrix.length];
		for(int i=0;i<matrix.length;i++)
			for(int j=0;j<matrix[i].length;j++)
				sum[i]=sum[i]+matrix[i][j];
		return sum;
	}
	
	public static int[] sumColumn(int[][] matrix){
		int sum[]= new int[matrix[0].length];
		for(int i=0;i<matrix.length;i++)
			for(int j=0;j<matrix[i].length;j++)
				sum[j]=sum[j]+matrix[i][j];
		return sum;
	}
}
